﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;

namespace Catering.View_Operaction
{
    public class View_Operaction_SystemFilter : IHttpModule
    {
       public String ModuleName
        {
            get { return "CatertingSystemFilter"; }
        }


       public View_Operaction_SystemFilter()
        {
            //
            //TODO: 在此处添加构造函数逻辑
            //
        }

        #region IHttpModule 成员

        void IHttpModule.Dispose()
        {
           // throw new NotImplementedException();
        }

        void IHttpModule.Init(HttpApplication context)
        {
            context.AcquireRequestState+=new EventHandler(context_AcquireRequestState);
             
        }

        void context_AcquireRequestState(object sender, EventArgs e)
        {
            HttpApplication application = (HttpApplication)sender;
            HttpContext context = application.Context;
            HttpSessionState session = context.Session;
            context.Request.ContentEncoding = System.Text.Encoding.UTF8;
            
          
            String contextPath = string.Empty;
            if (session!=null)
            {
                if (session["AM_USER_ID"] != null)
                {
                    HttpRequest request = context.Request;
                    HttpResponse response = context.Response;
                    contextPath = request.ApplicationPath;

                    
                }
                else
                {

                    if (context.Request.Url.ToString().IndexOf("login") < 1)
                        //跳转到登陆界面
                        //http://www.test.com/testweb/default.aspx 
                        //Request.ApplicationPath: /testweb  
                        //Request.CurrentExecutionFilePath: /testweb/default.aspx  
                        //Request.FilePath: /testweb/default.aspx  
                        //Request.Path: /testweb/default.aspx  
                        //Request.RawUrl: /testweb/default.aspx  
                        //Request.Url.AbsolutePath: /testweb/default.aspx  
                        //Request.Url.AbsoluteUri: http://www.test.com/testweb/default.aspx  
                        //Request.Url.Host: www.test.com  
                        //Request.Url.LocalPath: /testweb/default.aspx  


                        context.Response.Write("<script type='text/javascript'>window.parent.location.href='../login.aspx';</script>");
                    //context.Response.End();
                   
                      

                }
              
            }
           

        }

        #endregion
    }
}